<template>
  <div class="container">
    <div class="wrap">
      <el-row>
        <el-col :lg="16" :md="20" :sm="24" :xs="24">
          <el-form :model="form" status-icon ref="form" label-width="100px" @submit.native.prevent>
             <el-form-item label="用户名" prop="username">
              <el-input size="medium" v-model="form.username" placeholder="请填写用户名"></el-input>
            </el-form-item>
             <el-form-item label="邮箱" prop="email">
              <el-input type="medium" v-model="form.email" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item class="submit">
              <el-button type="primary" @click="submitForm('form')" :loading="loading">保 存</el-button>
              <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import warehouse from '@/model/omsuser'
import logVue from '../log/log.vue'
// import logVue from '../log/log.vue'

export default {
  props: {
    editWmsUserID: {
      type: Number,
    },
    pageType: {
      type: String,
      default: 'add', // 区分编辑页面/添加页面
    },
    info: {
      // 用户信息
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      loading: false,
      form: {
        username: '',
        email: '',
      },
    }
  },
  created() {
     if (this.pageType === 'edit') {
      console.log('edit');
      this.setInfo()
      this.isEdited = true
     }
  },
  async mounted() {
    // console.log('编辑数据',this.editWmsUserID);
    // this.loading = true
    // this.form = await warehouse.deleteWmsUserID(this.editWmsUserID)
    // this.loading = false
    // console.log(this.form);
  },
  methods: {
    async submitForm() {
      // 修改用户信息
      const res = await warehouse.editWmsUser(this.editWmsUserID, this.form)
      if (res.code < window.MAX_SUCCESS_CODE) {
        this.$message.success(`${res.message}`)
        this.$emit('editClose')
      }
    },
    setInfo() {
      console.log(111);
      console.log('信息',this.info);
      this.form = this.info
      // this.form.username = this.info.username
      // this.form.email = this.info.email
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
  },
}
</script>

<style lang="scss" scoped>
.el-divider--horizontal {
  margin: 0;
}

.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;

    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
